package org.cicd.devops

import org.cicd.enums.BuildType
import org.cicd.modle.AppInfoVars
import org.cicd.utils.utils

/**
 * 需要插件 SonarQube
 *
 * sonar扫描
 * @param buildType
 * @return
 */
def sonarScan(AppInfoVars appInfoVars) {
    def utils = new utils()
    utils.printMessage("代码扫描", "green")
    withSonarQubeEnv('SonarQube') {
        switch (appInfoVars.buildType) {
            case BuildType.MVN:
                //mvn
                sh "mvn clean verify sonar:sonar -Dmaven.test.skip=true -Dsonar.projectKey=${appInfoVars.appName} -Dsonar.projectName=${appInfoVars.appName} "
                break
            case BuildType.NPM:
                def scannerHome = tool 'Sonar_Scanner'
                sh """
                ${scannerHome}/bin/sonar-scanner -Dsonar.projectKey=${appInfoVars.appName} \
                -Dsonar.projectName=${appInfoVars.appName} \
                -Dsonar.sources=.
                """
                break
        }
    }
}
